import sys
sys.path.append('/Users/paolopuggioni/DTC/PhDcoding/MC Project/network_model/myfunctions')
import fast_network_analysis as fna
import netclass as nc
import net_analysis as na

import numpy
from scipy import *
from brian import *
import time

# ------------------- DICTIONARIES

Net_par={}
Syn_exc_par={}
Syn_inh_par={}
Syn_x_par={}
Pas_par={}
Fr_par={}
Init_par={}
Sim_par={}

# ------------------- NETWORK PARAMETERS
Net_par['Ne']=4000;
Net_par['Ni']=1000;
Net_par['Nx']=4000;

Net_par['Pee']=0.1;
Net_par['Pie']=0.1;
Net_par['Pei']=0.1;
Net_par['Pii']=0.1;
Net_par['Pex']=0.1;
Net_par['Pix']=0.1;

# ------------------- SYNAPTIC PARAMETERS



# --------- Excitatory
Syn_exc_par['tau']=0.002; # seconds
Syn_exc_par['Bee']=0.008*exp(1); #units of Gl
Syn_exc_par['Beestd']=Syn_exc_par['Bee']*0.8; 
Syn_exc_par['Bie']=0.016*exp(1); #units of Gl
Syn_exc_par['Biestd']=Syn_exc_par['Bie']*0.8; 

Syn_exc_par['WeightDist']='Normal'; #Normal/LogNormal


# --------- Inhibitory
Syn_inh_par['tau']=0.002; # seconds
Syn_inh_par['Bei']=0.075*exp(1); # units of Gl
Syn_inh_par['Beistd']=Syn_inh_par['Bei']*0.8; 
Syn_inh_par['Bii']=0.075*exp(1); # units of Gl
Syn_inh_par['Biistd']=Syn_inh_par['Bii']*0.8; 

Syn_inh_par['WeightDist']='Normal'; #Normal/LogNormal

# --------- External Drive
Syn_x_par['tau']=0.002; # seconds
Syn_x_par['Bex']=0.04*exp(1);  # units of gl
Syn_x_par['Bexstd']=Syn_x_par['Bex']*0.8; 
Syn_x_par['Bix']=0.04*exp(1);  # units of Gl
Syn_x_par['Bixstd']=Syn_x_par['Bix']*0.8; 

Syn_x_par['WeightDist']='Normal'; #Normal/LogNormal

# ---------------------------- PASSIVE PARAMETERS
Pas_par['C']=100. *10**(-12);
Pas_par['gl']=5.55 *10**(-9);

Pas_par['Ee']=0.;
Pas_par['Ei']=-75.;
Pas_par['El']=-62.;

Pas_par['thr']=-48.;
Pas_par['thr_res']=-52.;
Pas_par['tau_ref']=5.;

# ---------------------------- FREQUENCY PAR

Fr_par['x']=5.;



# ---------------------------- INITIALIZATION PAR
Init_par['V']=(-60.,0.01) # mean, std of gaussian distribution
Init_par['ge']=(0.,0.001)
Init_par['gi']=(0.,0.001)

# ---------------------------- SIMULATION PAR

Sim_par['duration']=5. #with 1000 it stops. Add counter of seconds during simulation and try again. in the worse case break the simulation into more pices. ask lukas how to keep the network structure the same.

Sim_par['lapse']=4.
Sim_par['Monitors_exc_size']=50
Sim_par['Monitors_inh_size']=50
monitor_step=1

# ---------------------------- STARTING

nm1=nc.IFnetwork(Net_par,Syn_exc_par,Syn_inh_par,Syn_x_par,Pas_par,Fr_par,Init_par,Sim_par)


nm1.buildPopulation()

nm1.buildConnection()

nm1.buildMonitors(Sim_par['Monitors_exc_size'],Sim_par['Monitors_inh_size'],Sim_par['lapse'],monitor_step)

nm1.initialParam()

nm1.runSim(Sim_par['duration'])

nm1.saveSpikes()

nm1.saveMonitors()


#nm1.grabResults()

#nm1.correlationcalc()

# nm1.loop1D(1,0,10,11)

# nm1.save_loop('fr_loop','../datasave/') # ('filename','folder/')






